const { Service, } = require('egg')

class UserService extends Service {
  async fetch() {
    const { app } = this
    let result = await app.mysql.query('select * from user')
    return result
  }

  async find(id) {
    const { app } = this
    let result = await app.mysql.select('user', {
      where: { id, },
      columns: [ 'id', 'username', 'age' ],
    })
    if (result) {
      result = result[0]
    }
    return result
  }
}

module.exports = UserService
